#!/bin/sh
#
# Starts dropbear sshd.
#

# Make sure the dropbear config directory exists
[ -d /etc/dropbear ] || mkdir -p /etc/dropbear

# Make sure the dropbearkey progam exists
[ -f /usr/bin/dropbearkey ] || exit 0

# Check for keys and generate if not present
[ -r /etc/dropbear/dropbear_dss_host_key ] || /usr/bin/dropbearkey -t dss -s 768 -f /etc/dropbear/dropbear_dss_host_key
[ -r /etc/dropbear/dropbear_rsa_host_key ] || /usr/bin/dropbearkey -t rsa -s 768 -f /etc/dropbear/dropbear_rsa_host_key

umask 077

start() {
 	echo -n "Starting dropbear sshd: "
	start-stop-daemon --start --quiet --pidfile /var/run/dropbear.pid --exec /usr/sbin/dropbear
	echo "OK"
}
stop() {
	echo -n "Stopping sshd: "
	start-stop-daemon --stop --quiet --pidfile /var/run/dropbear.pid
	echo "OK"
}
restart() {
	stop
	start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

